package 课堂作业api_day2;

import java.util.Scanner;

//需求6：切割字符串
//以字符串的形式从键盘录入学生信息，例如：“张三 , 23”
//从该字符串中切割出有效数据,封装为Student学生对象
public class TestDemo6 {
    public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
		System.out.println("请输入学生信息：");
    String s = scan.nextLine();//"张三,23"
        // 根据逗号切割字符串，得到（张三）（23）
    String[] str = s.split(",");

		for(int i = 0; i < str.length; i++) {
        System.out.println(str[i]);
    }
    Student stu = new Student(str[0],Integer.parseInt(str[1]));
		System.out.println(stu.getName() + "..." + stu.getAge());
    }
}

class Student{
    private String name;
    private int age;

    public Student() {}

    public Student(String name, int age) {
        super();
        this.name = name;
        this.age = age;
    }


    public String getName() {
        return name;
    }


    public void setName(String name) {
        this.name = name;
    }


    public int getAge() {
        return age;
    }


    public void setAge(int age) {
        this.age = age;
    }


    @Override
    public String toString() {
        return "Student [name=" + name + ", age=" + age + "]";
    }

}
